﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Chapter_9__Recursion_
{
    public class SortableSortedSet<T> : SortedSet<T>, IComparable where T : IComparable
    {
        public SortableSortedSet()
            : base()
        {
        }

        public SortableSortedSet(SortedSet<T> SortedSet)
            : base(SortedSet)
        {
        }

        public int CompareTo(object obj)
        {
            SortableSortedSet<T> Set = obj as SortableSortedSet<T>;
            int result = this.Count.CompareTo(Set.Count);

            if (result == 0)
            {
                Enumerator enum1 = this.GetEnumerator();
                Enumerator enum2 = Set.GetEnumerator();

                while (enum1.MoveNext() && enum2.MoveNext() && result == 0)
                {
                    result = enum1.Current.CompareTo(enum2.Current);
                }
            }

            return result;
        }
    }
}
